<template>
  <div>
    <f-search-form :more='true' @searchHandler='searchHandler'>
      <f-search-form-item label='单位名称' name='customId' type='select' :data='api.custom.listByName' :params='queryParam' value-key='customId' label-key='customName' :show-all='false' :show-search='true' />
      <f-search-form-item label='部门' ref='dept' name='deptId' type='select' :data='this.api.hyorder.listByCompanyId' valueKey='deptId' label-key='deptName' />
      <f-search-form-item label='单号' name='paymentNo' slot='advanced' />
      <f-search-form-item label='收款日期' type='date' name='amountDate' slot='advanced' />
    </f-search-form>
    <f-table ref='table' size='small' rowKey='paymentId' :columns='columns' :scroll='{x:true}' :multiple='false' :operator='operator' :params='queryParam' :api='api.tasktodo' handler='hyAskAmountTaskTab1Handler'>
      <span slot='amountType' slot-scope='text, record, index'>
         <a-tag color='#87d068' v-if="text=='CustomRefund'">回款认款</a-tag>
         <a-tag color='#87d068' v-if="text=='CustomBond'">资保金认款</a-tag>
         <a-tag color='#87d068' v-if="text=='OrderAmount'">现款认款</a-tag>
         <a-tag color='#108ee9' v-if="text=='YfkAmount'">预收款认款</a-tag>
         <a-tag color='#108ee9' v-if="text=='DepositAmount'">保证金认款</a-tag>
      </span>
      <span slot='hkImage' slot-scope='text, record, index'>
          <f-images :value='record.hkImage'></f-images>
      </span>
      <span slot='taskName' slot-scope='text, record, index'>
          <a-tag color='#87d068' @click='processImg(record)'>{{ record.taskName }}</a-tag>
      </span>

      <span slot='action' slot-scope='text, record'>
          <template>
            <a v-if="record.endTime==''&&record.assignee!=''&& record.assignee!=''" @click='$refs.drawer.showDrawer(record)'>办理</a>
            <a v-if="record.assignee==''||record.assignee==''" @click='claimTask(record)'>认领</a>
             <a-divider type='vertical' />
              <a href='javascript:;' @click="$refs['returnDetailsDrawer'].showDrawer(record)" v-if='record.amountType=="CustomRefund"'>查看</a>
              <a-divider type='vertical' v-if='record.amountType=="CustomRefund"' />
          </template>
          <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
               <a-menu-item v-if="record.assignee===$store.getters.userInfo.nickName && record.endTime==''">
                <a href='javascript:;' @click='unClaimTask(record)'>取消认领</a>
              </a-menu-item>
                <a-menu-item>
                <a href='javascript:;' @click='processImg(record)'>流程图</a>
              </a-menu-item>
               <a-menu-item v-if='!record.paymentId'>
                  <a href='javascript:;' @click='deleteProcessInstance(record.processInstanceId)'>删除审批流程</a>
                </a-menu-item>
              <a-menu-item v-if='record.amountType!="CustomRefund"'>
                <a href='javascript:;' @click='printPayment(record.paymentId)'>查看认款单</a>
              </a-menu-item>
                <a-menu-item v-if='record.amountType=="CustomRefund"'>
                <a href='javascript:;' @click='printPayment6(record.paymentId)'>查看认款单</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
    </f-table>
    <task-todo-drawer ref='drawer' @success='onLoad' handler-name='hyAskAmountTaskDataHandler'></task-todo-drawer>
    <process-image ref='processImg' v-if='processImageVisible' :visible.sync='processImageVisible' :processInstanceId='processInstanceId'></process-image>
    <return-details-drawer ref='returnDetailsDrawer'></return-details-drawer>
    <print-modal ref='printModal' :showPrint='false'></print-modal>
  </div>
</template>
<script>

import api from "../../js/api"
import ProcessImage from "../../../flowable/process/process_image"
import TaskTodoDrawer from "../tasktodo_drawer"
import ReturnDetailsDrawer from "@/views/module/haiying/order/return/components/return_details_drawer"
import { processMixins } from "@/core/mixins/processMixins"
import PrintModal from "../../print/print_modal"

export default {
  name: "TableList",
  components: {
    ReturnDetailsDrawer,
    ProcessImage,
    PrintModal,
    TaskTodoDrawer
  },
  mixins: [processMixins],
  data() {
    let me = this
    //操作按钮
    let operator = []

    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {},
      scroll: { x: true },
      companyList: [],
      // 表头
      columns: [
        {
          title: "序号",
          width: "50px",
          align: "center",
          fixed: "left",
          customRender: (text, record, index) => index + 1
        },
        {
          title: "认款单号",
          align: "center",
          fixed: "left",
          dataIndex: "paymentNo"
        },
        {
          title: "单据类型",
          align: "center",
          width: "100px",
          dataIndex: "amountType",
          scopedSlots: { customRender: "amountType" },
          filters: [
            {
              text: "资保金认款",
              value: "CustomBond"
            },
            {
              text: "预收款",
              value: "YfkAmount"
            },
            {
              text: "现款认款",
              value: "OrderAmount"
            },
            {
              text: "保证金",
              value: "DepositAmount"
            }
          ],
          filterMultiple: false
        },
        {
          title: "部门名称",
          align: "left",
          width: "150px",
          dataIndex: "deptName"
        },
        {
          title: "业务员",
          align: "left",
          width: "90px",
          ellipsis: true,
          dataIndex: "saleManName"
        },
        {
          title: "业务编码",
          align: "left",
          width: "120px",
          dataIndex: "businessCode"
        },
        {
          title: "回款单位",
          align: "left",
          width: "100px",
          ellipsis: true,
          dataIndex: "payUserName"
        },
        {
          title: "回款金额",
          align: "left",
          width: "80px",
          dataIndex: "amount"
        },
        {
          title: "回款日期",
          align: "left",
          width: "100px",
          dataIndex: "amountDate"
        },
        {
          title: "收款银行",
          align: "left",
          width: "120px",
          dataIndex: "bankName"
        },
       
        {
          title: "制单人",
          align: "left",
          width: "80px",
          dataIndex: "nickName"
        },
        {
          title: "创建日期",
          align: "left",
          dataIndex: "createTime"
        },
        {
          title: "备注",
          align: "left",
          dataIndex: "remark",
          width: "100px"
        },
        {
          title: "审批状态",
          align: "left",
          fixed: "right",
          width: "130px",
          dataIndex: "taskName",
          scopedSlots: { customRender: "taskName" }
        },

        {
          title: "操作",
          align: "center",
          dataIndex: "action",
          width: "145px",
          fixed: "right",
          scopedSlots: { customRender: "action" }
        }
      ],
      operator: operator
    }
  },
  created() {

  },
  methods: {
    onLoad() {
      this.$refs.table.refresh()
    },
    /**
     * 取消认领
     * @param task
     */
    unClaimTask(task) {
      this.http.put(this, {
        url: this.api.tasktodo.unclaim,
        data: {
          taskId: task.taskId
        },
        success(me, data) {
          me.$refs["table"].refresh(false)
        }
      })
    },
    /**
     * 查询事件
     * @param searchParams
     */
    searchTable(searchParams) {
      this.queryParam = Object.assign(this.queryParam, searchParams)
      this.$refs.table.refresh(true, searchParams)
    },
    //打印单
    printPayment(paymentId) {
      this.$refs["printModal"].open(paymentId, 4, "YfkAmount")
    },
    //打印单
    printPayment6(paymentId) {
      this.$refs["printModal"].open(paymentId, 6, "YfkAmount")
    }
  }
}
</script>
